<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理页面</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
</head>
<body>
<ul class="layui-nav layui-bg-green" lay-filter="">
    <li class="layui-nav-item layui-this"><a href="/room/mahjong/index">房间列表</a></li>
    <li class="layui-nav-item"><a href="/room/findTypes">新增房间</a></li>
    <li class="layui-nav-item"><a href="/user/mahjong/user_manage">用户列表</a></li>
    <li class="layui-nav-item"><a href="/user/mahjong/user_add">添加用户</a></li>
    <li class="layui-nav-item"><a href="/order/mahjong/order_handler">订单管理</a></li>
    <li class="layui-nav-item layui-col-md-offset4">
        <a href=""><img src="http://localhost:8083/img.jpg" class="layui-nav-img"/>管理员</a>
    </li>
    <li class="layui-nav-item"><a href="/account/logout">退出</a></li>
</ul>
<div class="layui-container" style="width: 640px;height: 600px;margin-top: 0px;padding-top: 60px;">

    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn  layui-btn-sm layui-btn-normal" lay-event="update">修改</a>
        <a class="layui-btn  layui-btn-sm layui-btn-warm" lay-event="delete">删除</a>
    </script>
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <script>
        layui.use('table', function(){
            var table = layui.table;

            table.render({
                elem: '#test'
                ,url:'/room/findAll'
                ,title: '房间列表'
                ,cols: [
                    [
                        {field:'id', width:100, title: '编号', sort: true}
                        ,{field:'name', width:100, title: '房间'}
                        ,{field:'price', width:80, title: '价格'}
                        ,{field:'size', width:80, title: '大小'}
                        ,{field:'type',width:80,  title: '分类', templet:function(data){
                            return data.type.name
                            }
                        }
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:140}
                    ]
                ]
                ,page: true
            });


            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'update'){
                    window.location.href="/room/findById/"+data.id;
                }
                if(obj.event === 'delete'){
                    layer.confirm('确定要删除？',function (index){
                       window.location.href="/room/deleteById/"+data.id;
                       layer.close(index);
                    });
                }
            });
        });
    </script>

</div>
</body>
</html>